package com.totoro.tyrank.executor.command.impl;

import com.totoro.tyrank.TyRank;
import com.totoro.tyrank.constants.InvRankTypeConst;
import com.totoro.tyrank.data.RankingData;
import com.totoro.tyrank.executor.command.MainCommandExecutor;
import com.totoro.tyrank.inventory.AttributeReceiveInventory;
import com.totoro.tyrank.inventory.CurrentRankInventory;
import com.totoro.tyrank.inventory.RankContentInventory;
import com.totoro.tyrank.inventory.RewardReceiveInventory;
import com.totoro.tyrank.utils.ColorUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Map;

public class OpenCommandExecutor implements MainCommandExecutor {
    @Override
    public void execute(CommandSender sender, String[] args) {
        if(! (sender instanceof Player)) {
            return;
        }
        Player player = (Player) sender;
        // 大小是2是打开某个排行榜界面
        if(args.length == 2) {
            // 获取当前打开的排行榜Id
            String rankId = args[1];
            Map<String, RankingData> rankDataMap = TyRank.getRankingManager().getRankDataMap();
            if(rankDataMap.containsKey(rankId)) {
                // 打开某个排行榜界面
                RankContentInventory.openMainInv(player, rankId, InvRankTypeConst.ALL_RANK_INV);
                return;
            }
            player.sendMessage(TyRank.getConfigManager().getConfigData().getPrefix() +
                    TyRank.getLanguageManager().getLanguageData().getMsg().getInputRankIdError());
        }
        // 大小是3则是打开某个排行榜的属性预览或者奖励预览
        else if (args.length == 3) {
            // 获取当前打开的排行榜Id
            String rankId = args[1];
            // 获取当前打开的是属性预览还是奖励预览
            String receiveType = args[2];
            if(!receiveType.equals("reward") && !receiveType.equals("attribute")) {
                player.sendMessage(TyRank.getConfigManager().getConfigData().getPrefix() +
                        ColorUtil.color("&c参数输入错误，正确使用方式：/tyrank open <排行榜Id> <reward|attribute>(可忽略)"));
                return;
            }
            if(receiveType.equals("reward")) {
                RewardReceiveInventory.openMainInv(player, rankId, InvRankTypeConst.ALL_RANK_INV);
            } else {
                AttributeReceiveInventory.openMainInv(player, rankId, InvRankTypeConst.ALL_RANK_INV);
            }
        }
        else {
            player.sendMessage(TyRank.getConfigManager().getConfigData().getPrefix() +
                    ColorUtil.color("&c参数输入错误，正确使用方式：/tyrank open <排行榜Id> <reward|attribute>(可忽略)"));
        }
    }
}
